//
//  OrderDetailTradeCell.m
//  danpin
//
//  Created by chuangjia on 29/10/2015.
//  Copyright © 2015 chuangjia. All rights reserved.
//

#import "OrderDetailTradeCell.h"
#import "HTCopyableLabel.h"
@interface OrderDetailTradeCell ()
{
    
}
@property(nonatomic,strong)HTCopyableLabel *noLabel;
@property(nonatomic,strong)UIView *line2view;
//
@property(nonatomic,strong)UILabel *statueLabel;
@property(nonatomic,strong)UIView *lineview;
//
@property(nonatomic,strong)UIButton *cancelbtn;
@property(nonatomic,strong)UIButton *helpbtn;
@property(nonatomic,strong)UILabel *ddyfkey;


@end
@implementation OrderDetailTradeCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor=[UIColor clearColor];
        
        _noLabel =[[HTCopyableLabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH,20)];
        _noLabel.backgroundColor = [UIColor clearColor];
        _noLabel.textColor = CONTEXT_COLOR;
        _noLabel.textAlignment = NSTextAlignmentLeft;
        _noLabel.font = FONT(12);
        [self.contentView addSubview:_noLabel];
        
        _line2view =[[UIView alloc] initWithFrame:CGRectZero];
        _line2view.backgroundColor=UIColorFromRGB(0xcccccc);
        [self.contentView addSubview:_line2view];
        //
        _statueLabel =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH,20)];
        _statueLabel.backgroundColor = [UIColor clearColor];
        _statueLabel.textColor = CONTEXT_COLOR;
        _statueLabel.textAlignment = NSTextAlignmentLeft;
        _statueLabel.font = FONT(12);
        [self.contentView addSubview:_statueLabel];
        
        _helpbtn =[UIButton buttonWithType:UIButtonTypeCustom];
        _helpbtn.backgroundColor = [UIColor clearColor];
        _helpbtn.layer.borderColor = [UIColor redColor].CGColor;
        _helpbtn.layer.borderWidth = 1;
        _helpbtn.tag =1;
        _helpbtn.titleLabel.font = FONT(12);
        _helpbtn.hidden = YES;
        [_helpbtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [_helpbtn setTitle:@"立即支付" forState:UIControlStateNormal];
        [_helpbtn addTarget:self action:@selector(clickHelpEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_helpbtn];
        
        _cancelbtn =[UIButton buttonWithType:UIButtonTypeCustom];
        _cancelbtn.backgroundColor = [UIColor clearColor];
        _cancelbtn.layer.borderColor = [UIColor redColor].CGColor;
        _cancelbtn.layer.borderWidth = 1;
         _cancelbtn.tag =2;
        _cancelbtn.titleLabel.font = FONT(12);
        _cancelbtn.hidden = YES;
        [_cancelbtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [_cancelbtn setTitle:@"取消订单" forState:UIControlStateNormal];
        [_cancelbtn addTarget:self action:@selector(clickHelpEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_cancelbtn];
        
        _lineview =[[UIView alloc] initWithFrame:CGRectZero];
        _lineview.backgroundColor=UIColorFromRGB(0xcccccc);
        [self.contentView addSubview:_lineview];
        //
        _ddyfkey =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH,20)];
        _ddyfkey.backgroundColor = [UIColor clearColor];
        _ddyfkey.textColor = CONTEXT_COLOR;
        _ddyfkey.textAlignment = NSTextAlignmentLeft;
        _ddyfkey.font = FONT(12);
        [self.contentView addSubview:_ddyfkey];
        
        
    }
    return self;
}
-(void)dealloc
{
    self.actionBlock =nil;
    self.data=nil;
    self.indexPath=nil;
    self.other=nil;
    self.key=nil;
    
    //    DLog(@"%s", __PRETTY_FUNCTION__);
}
- (void)drawRect:(CGRect)rect {
    
    [super drawRect:rect];
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
}

/// 根据数据模型来显示内容
- (void)showInfo:(id)model key:(id)key indexPath:(NSIndexPath *)indexPath
{
    self.key =key;
    self.indexPath=indexPath;
    NSDictionary *dict =(NSDictionary*)model;
    self.data =model;
    
    _noLabel.frame =CGRectMake(PHOTO_FRAME_WIDTH, PHOTO_FRAME_WIDTH,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2, 20);
    NSString *out_trade_no =[dict stringForKey:@"out_trade_no" withDefaultValue:@""];
    _noLabel.text = [NSString stringWithFormat:@"订单号: %@",out_trade_no];
    _line2view.frame =CGRectMake(PHOTO_FRAME_WIDTH, PHOTO_FRAME_WIDTH+30,DEVICE_WIDTH, 0.5);
    
    //
    _statueLabel.frame =CGRectMake(PHOTO_FRAME_WIDTH, PHOTO_FRAME_WIDTH*5,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2, 20);
    NSString *status_zh =[dict stringForKey:@"status_zh" withDefaultValue:@""];
    _statueLabel.text = [NSString stringWithFormat:@"订单状态: %@",status_zh];
    if ([[dict objectForKey:@"status"] intValue]==0) {
         _helpbtn.hidden=NO;
        _cancelbtn.hidden=NO;
        _helpbtn.frame=CGRectMake(DEVICE_WIDTH-PHOTO_FRAME_WIDTH*7, PHOTO_FRAME_WIDTH*5,PHOTO_FRAME_WIDTH*6, 20);
        _cancelbtn.frame =CGRectMake(_helpbtn.frame.origin.x-PHOTO_FRAME_WIDTH*7, PHOTO_FRAME_WIDTH*5,PHOTO_FRAME_WIDTH*6, 20);
    }else{
        _helpbtn.hidden=YES;
        _cancelbtn.frame =CGRectZero;
        _cancelbtn.hidden=YES;
    }
    _lineview.frame =CGRectMake(PHOTO_FRAME_WIDTH, PHOTO_FRAME_WIDTH*8,DEVICE_WIDTH, 0.5);
    //
    NSString *add_time =[dict stringForKey:@"add_time" withDefaultValue:@""];
    _ddyfkey.frame =CGRectMake(PHOTO_FRAME_WIDTH, PHOTO_FRAME_WIDTH*9,DEVICE_WIDTH, 20);
    _ddyfkey.text = [NSString stringWithFormat:@"下单时间: %@",add_time];
    [self layoutSubviews];
}
-(void)setCallBack:(void(^)(BEventType,UIView*,id,id,NSIndexPath *))callback
{
    self.actionBlock=callback;
}
-(void)clickHelpEvent:(id)sender
{
    UIButton *btn = (UIButton *)sender;
    switch (btn.tag) {
        case 1:
        {
            if (self.actionBlock) {
                self.actionBlock(BEventType_help,nil,self.data,nil,self.indexPath);
            }
        }
            break;
        case 2:
        {
            if (self.actionBlock) {
                self.actionBlock(BEventType_cancelOrder,nil,self.data,nil,self.indexPath);
            }
        }
            break;
        default:
            break;
    }
   
}
/// 返回Cell高度
+ (CGFloat)returnCellHeight:(id)model
{
    return PHOTO_FRAME_WIDTH*12;
}


@end
